package main

import (
	"fmt"

	"github.com/garyburd/redigo/redis"
	"time"
)

type redisObj struct {
	option redis.DialOption
	conn redis.Conn
}

func main() {
	var redisObject redisObj
	var err error

	redisObject.option = redis.DialPassword("123456")

	redisObject.conn, err = redis.Dial("tcp", "192.168.0.222:6379", redisObject.option)
	if err != nil {
		fmt.Println("Connect to redis error", redisObject.conn)
		return
	}
	defer redisObject.conn.Close()

	redisObject.sadd()
	//redisObject.spop()

}

// 添加redis
func (redis redisObj) sadd() {
	sadd_match_user := time.Now().Format("20060102") + "_match_user_1"
	for i := 1; i <= 1000000;  i++{
		_, err := redis.conn.Do("SADD", sadd_match_user, i)
		if err != nil {
			fmt.Println("redis set failed:", err)
		}
	}
}

// 取出redis
func (r redisObj) spop()  {
	match_user := time.Now().Format("20060102") + "_match_user_1"
	for i := 1; i<= 100;  i++{
		value, err := redis.String(r.conn.Do("SPOP", match_user))

		if err == nil {
			fmt.Printf("value： %v - time: %s \n", value, time.Now().Format("2006-01-02 15:04:05"))
		} else {
			fmt.Printf("no: %s \n", time.Now().Format("2006-01-02 15:04:05"))
		}
	}
}